#
# Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
#

# -*- mode: python; -*-

Import('BuildEnv')
import platform
import os

env = BuildEnv.Clone()

env.Append(CPPPATH = [env['TOP'],
                      env['TOP'] + '/db',
                      env['TOP'] + '/io',
                      env['TOP'] + '/tools/sandesh/library/common',
                     ])

env.Append(LIBPATH = env['TOP'] + '/base')
env.Append(LIBPATH = env['TOP'] + '/base/test')
env.Append(LIBPATH = env['TOP'] + '/bgp')
env.Append(LIBPATH = env['TOP'] + '/bgp/inet')
env.Append(LIBPATH = env['TOP'] + '/bgp/inet6')
env.Append(LIBPATH = env['TOP'] + '/bgp/inet6vpn')
env.Append(LIBPATH = env['TOP'] + '/bgp/evpn')
env.Append(LIBPATH = env['TOP'] + '/bgp/ermvpn')
env.Append(LIBPATH = env['TOP'] + '/bgp/mvpn')
env.Append(LIBPATH = env['TOP'] + '/bgp/test')
env.Append(LIBPATH = env['TOP'] + '/bgp/l3vpn')
env.Append(LIBPATH = env['TOP'] + '/bgp/origin-vn')
env.Append(LIBPATH = env['TOP'] + '/bgp/routing-instance')
env.Append(LIBPATH = env['TOP'] + '/bgp/routing-policy')
env.Append(LIBPATH = env['TOP'] + '/bgp/rtarget')
env.Append(LIBPATH = env['TOP'] + '/bgp/security_group')
env.Append(LIBPATH = env['TOP'] + '/bgp/tunnel_encap')
env.Append(LIBPATH = env['TOP'] + '/control-node')
env.Append(LIBPATH = env['TOP'] + '/db')
env.Append(LIBPATH = env['TOP'] + '/io')
env.Append(LIBPATH = env['TOP'] + '/ifmap')
env.Append(LIBPATH = env['TOP'] + '/net')
env.Append(LIBPATH = env['TOP'] + '/bgp/extended-community')
env.Append(LIBPATH = env['TOP'] + '/route')
env.Append(LIBPATH = env['TOP'] + '/xmpp')
env.Append(LIBPATH = env['TOP'] + '/xml')
env.Append(LIBPATH = env['TOP'] + '/schema')

etcd_incl = os.environ.get('CONTRAIL_ETCD_INCL');

if etcd_incl:
    env.Prepend(LIBS = [
                    'etcdql',
                    'protobuf',
                    'grpc++',
                    'grpc',
                    'z'
                    ])

env.Prepend(LIBS = [
                    'task_test',
                    'bgptest',
                    'bgp',
                    'bgp_ifmap_config',
                    'peer_sandesh',
                    'control_node',
                    'origin_vn',
                    'routing_instance',
                    'routing_policy',
                    'rtarget',
                    'security_group',
                    'tunnel_encap',
                    'ifmap_vnc',
                    'bgp_schema',
                    'sandesh',
                    'http',
                    'http_parser',
                    'curl',
                    'ifmapio',
                    'ifmap_server',
                    'config_client_mgr',
                    'ifmap_common',
                    'base',
                    'db',
                    'gunit',
                    'io',
                    'crypto',
                    'ssl',
                    'sandeshvns',
                    'net',
                    'route',
                    'xmpp',
                    'bgp_inet',
                    'bgp_inet6',
                    'bgp_inet6vpn',
                    'bgp_ermvpn',
                    'bgp_mvpn',
                    'bgp_evpn',
                    'bgp_l3vpn',
                    'xmpp_unicast',
                    'xmpp_multicast',
                    'xmpp_enet',
                    'xml',
                    'pugixml',
                    'boost_regex',
                    'process_info',
                    'io',
                    'cassandra_cql',
                    'SimpleAmqpClient',
                    'rabbitmq',
                    'cassandra',
                    'gendb',
                    'boost_chrono'])

if platform.system() != 'Darwin':
    env.Append(LIBS=['rt', 'extended_community'])
    env.Prepend(LINKFLAGS = ['-Wl,--whole-archive',
                             '-lbgp_ermvpn',
                             '-lbgp_mvpn',
                             '-lbgp_evpn',
                             '-lbgp_inet',
                             '-lbgp_inet6',
                             '-lbgp_inet6vpn',
                             '-lbgp_l3vpn',
                             '-lrtarget',
                             '-ltask_test',
                             '-Wl,--no-whole-archive'])
else:
    lib_ermvpn = Dir('../../ermvpn').path + '/libbgp_ermvpn.a'
    env.Prepend(LINKFLAGS = ['-Wl,-force_load,' + lib_ermvpn])
    lib_mvpn = Dir('../../mvpn').path + '/libbgp_mvpn.a'
    env.Prepend(LINKFLAGS = ['-Wl,-force_load,' + lib_mvpn])
    lib_evpn = Dir('../../evpn').path + '/libbgp_evpn.a'
    env.Prepend(LINKFLAGS = ['-Wl,-force_load,' + lib_evpn])
    lib_inet = Dir('../../inet').path + '/libbgp_inet.a'
    env.Prepend(LINKFLAGS = ['-Wl,-force_load,' + lib_inet])
    lib_inet6 = Dir('../../inet6').path + '/libbgp_inet6.a'
    env.Prepend(LINKFLAGS = ['-Wl,-force_load,' + lib_inet6])
    lib_inet6vpn = Dir('../../inet6vpn').path + '/libbgp_inet6vpn.a'
    env.Prepend(LINKFLAGS = ['-Wl,-force_load,' + lib_inet6vpn])
    lib_l3vpn = Dir('../../l3vpn').path + '/libbgp_l3vpn.a'
    env.Prepend(LINKFLAGS = ['-Wl,-force_load,' + lib_l3vpn])
    lib_rtarget = Dir('../../rtarget').path + '/librtarget.a'
    env.Prepend(LINKFLAGS = ['-Wl,-force_load,' + lib_rtarget])

inet_route_test = env.UnitTest('inet_route_test', ['inet_route_test.cc'])
env.Alias('src/bgp/inet:inet_route_test', inet_route_test)

inet_table_test = env.UnitTest('inet_table_test', ['inet_table_test.cc'])
env.Alias('src/bgp/inet:inet_table_test', inet_table_test)

test_suite = [
    inet_route_test,
    inet_table_test,
]

test = env.TestSuite('bgp-test', test_suite)
env.Alias('controller/src/bgp/inet:test', test)

Return('test_suite')
